package com.phamloc.fastconnect.objects;

import java.util.ArrayList;

import org.andengine.entity.primitive.Line;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;

import android.graphics.PointF;

import com.phamloc.fastconnect.extras.Pair;

public class Shape {
 	public	ArrayList<PointF> Vertex;
	public ArrayList<Pair> Edge;
	
	public Shape() {
		Vertex = new ArrayList<PointF>();
		Edge = new ArrayList<Pair>();
	}

	public ArrayList<PointF> getVertex() {
		return Vertex;
	}
	
	public Shape(ArrayList<PointF> vertex, ArrayList<Pair> edge) {
		super();
		Vertex = vertex;
		Edge = edge;
	}

	public void setVertex(ArrayList<PointF> vertex) {
		Vertex = vertex;
	}
	public ArrayList<Pair> getEdge() {
		return Edge;
	}
	public void setEdge(ArrayList<Pair> edge) {
		Edge = edge;
	}
	public void draw(Color color, Sprite background, VertexBufferObjectManager vbom) {
		for(Pair p : this.Edge){
			Line line = new Line(Vertex.get(p.getFirst()).x, Vertex.get(p.getFirst()).y, Vertex.get(p.getSecond()).x, Vertex.get(p.getSecond()).y, vbom);
			line.setColor(color);
			background.attachChild(line);
		}
	}
	public int IndexOfVetex(PointF point) {
		int  i = 0;
		for(PointF p : Vertex){
			if((int)point.x == (int)p.x && (int)point.y == (int)p.y){
				return i;
			}
			i++;
		}
		return -1;
	}
	public boolean containsEdge(int a,int b){
		for (Pair p : Edge) {
			if( (p.getFirst() == a && p.getSecond() == b) || p.getFirst() == b && p.getSecond() == a){
				return true;
			}
		}
		return false;
	}
	public boolean containsEdge(Pair edge){
		return containsEdge(edge.getFirst(), edge.getSecond());
	}
}
